import Opt from '@/components/dt/info/Opt.js'
import dateOpt from '@/biz/option/date.js'

class ColumnOpt extends Opt {
  constructor() {
    super()
    this.build()
  }

  build() {
    this.createAll()
    this.opts.push(...this.all)
  }

  createAll() {
    this.all = [
      {
        field: 'caseLocationTwo',
        title: '所属组织',
        minWidth: 150
      },
      {
        field: 'city',
        title: '所属城市',
        minWidth: 110
      },
      {
        field: 'housesName',
        title: '案场名称',
        minWidth: 160
      },
      {
        field: 'backAmount',
        title: '回款金额(元)',
        minWidth: 150,
        cell: {
          text: {
            type: 'number'
          }
        }
      },
      {
        field: 'backType',
        minWidth: 100,
        cell: {
          text: {
            type: 'dict',
            key: 'backType'
          }
        },
        header: {
          filter: {
            title: '回款类型',
            key: 'backType',
            placeholder: '请选择',
            select: {
              key: 'backType'
            }
          }
        }
      },
      {
        field: 'backDate',
        title: '回款日期',
        minWidth: 120,
        cell: {
          text: {
            type: 'date'
          }
        },
        header: {
          filter: dateOpt.range({
            title: '回款日期',
            startKey: 'backStartDate',
            endKey: 'backEndDate'
          })
        }
      },
      {
        field: 'writeOffAmount',
        title: '已销金额(元)',
        minWidth: 150,
        cell: {
          text: {
            type: 'number'
          }
        }
      },
      {
        field: 'waitWriteOffAmount',
        title: '待销金额(元)',
        minWidth: 150,
        cell: {
          text: {
            type: 'number'
          }
        }
      },
      {
        field: 'status',
        title: '核销状态',
        minWidth: 100,
        cell: {
          text: {
            type: 'dict',
            key: 'WriteOffStatus'
          }
        }
      },
      {
        field: 'attaches',
        title: '回单状态',
        minWidth: 100,
        cell: {
          value: (info) => (info.attaches?.length > 0 ? '已上传' : '未上传'),
          text: {}
        },
        header: {
          filter: {
            title: '回单状态',
            key: 'isUploadBackAttach',
            placeholder: '请选择',
            select: {
              options: [
                { key: 1, value: '已上传' },
                { key: 0, value: '未上传' }
              ]
            },
            data: {
              from: (info) => (info.isUploadBackAttach ? '1' : info.isUploadBackAttach == false ? '0' : null),
              to: (val) => ({ isUploadBackAttach: val.value == 1 })
            }
          }
        }
      },
      {
        field: 'createTime',
        title: '创建日期',
        minWidth: 120,
        cell: {
          text: {
            type: 'date'
          }
        }
      },
      {
        field: 'handles',
        title: '操作',
        width: 160,
        fixed: 'right',
        cell: (item) => {
          return {
            btn: [
              {
                title: '查看',
                event: 'onDetail'
              },
              {
                title: '回单上传',
                event: 'onUpload',
                code: '0210030300',
                visible: !(item.attaches?.length > 0)
              },
              {
                title: '删除',
                event: 'onDelete',
                code: '0210030200',
                visible: item.status === 'NO_WRITE_OFF'
              }
            ]
          }
        }
      }
    ]
  }
}

export default ColumnOpt
